export type ProductDataType = {
  id: number;
  title: string;
  description: string;
  price: number;
  tags: string[];
  thumbnail: string;
}

export const getProducts = async () => {
  const res = await fetch(
    'https://dummyjson.com/products',
    // { cache: 'force-cache' }   // getStaticProps (pages router)
    // { cache: 'no-store' }      // getServerSideProps (pages router)
    // { next: { revalidate: 3600 } } // Incremental Static Regeneration (getStaticProps with revalidate)
  )
  if (!res.ok) throw new Error('fetch products failed!')
  return await res.json()
}

export const getProductDetails = async (id:string) => {
  const res = await fetch(
    `https://dummyjson.com/products/${id}`
  )
  if (!res.ok) throw new Error('fetch product data failed!')
  return await res.json()
}
